//2009/09/10 06:25:04
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

class TheCardLineDivTwo
{
public:
    int count(vector <string> cards)
    {
		vector<pair<char, char> > v(cards.size());
		for(int i=0; i<cards.size(); i++)
		{
			v[i].first = cards[i][0];
			v[i].second = cards[i][1];
		}
		sort(v.begin(), v.end());
        long long cnt = 0;
        do
        {
            bool flag = true;
            for (int i=0; i+1<cards.size(); i++)
            {
                if (v[i].first==v[i+1].first || iscolor(v[i].second,v[i+1].second)) continue;
                else
                {
                    flag = false;
                    break;
                }
            }
            if (flag)
            {
                cnt = cnt + 1;
            }
            //for (int i=0; i<cards.size(); i++) cout << v[i].first << v[i].second << ", ";
            //cout << endl;
        }
        while (next_permutation(v.begin(), v.end()));
        return cnt % 1234567891;
    }
    bool iscolor(char c, char d)
    {
        if ((c=='H'&&d=='H') ||(c=='H'&&d=='D') || (c=='D'&&d=='H') || (c=='D'&&d=='D')) return true;
        if ((c=='C'&&d=='C') ||(c=='C'&&d=='S') || (c=='S'&&d=='C') || (c=='S'&&d=='S')) return true;
        return false;
    }
};
